package salb1;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Read time of operations for variants.
 * In columns are variants
 * In rows are operations
 * @author krzysiek
 *
 */
public class TimeOfOperations {
    
    private List<List<Integer>> timeOfOperations = new ArrayList<List<Integer>>();;
    private int numOfOperations = 0; 
    private int numOfVariants = 0;
    private int numOfMachines;
    
    public TimeOfOperations(String path) {
          
        try {
            BufferedReader in = new BufferedReader(new FileReader(path));     

            // first line is number of machines
            numOfMachines = Integer.parseInt(in.readLine());

            String str;
            while ((str = in.readLine()) != null)
            {
                String[] timeOfOperationsForVariantStrings = str.split("\\s+");
                if (this.numOfVariants == 0) {
                    this.numOfVariants = timeOfOperationsForVariantStrings.length;
                }
                List<Integer> timeOfOperationsForVariantIntegers = new ArrayList<Integer>(this.numOfOperations);
                for (String timeStr : timeOfOperationsForVariantStrings) {
                    timeOfOperationsForVariantIntegers.add(new Integer(timeStr));
                }

                timeOfOperations.add(timeOfOperationsForVariantIntegers); 
            }
            in.close();
            this.numOfOperations = timeOfOperations.size();
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
        
    }
    
    public void printTimeOfOperations() {
        
        System.out.println("Num of machines : "+numOfMachines);
        
        for (List<Integer> timeOfOperation : timeOfOperations) {
            for (Integer timeOfVariant : timeOfOperation) {
                System.out.print(timeOfVariant+" ");
            }
            System.out.println();
        }
    }
    
    public int getNumOfOperations() {
        return numOfOperations;
    }
    
    public int getNumOfVariants() {
        return numOfVariants;
    }
    
    public static void main(String[] args) {
        
        try {
            TimeOfOperations top = new TimeOfOperations("input.txt");
            top.printTimeOfOperations();
        
        } 
        catch (Exception e) { e.printStackTrace(); }
    }

    public int getNumOfStations() {
        return this.numOfMachines;
    }

    public int getTimeOf(int operationNum, int variantNum) {
        return timeOfOperations.get(operationNum).get(variantNum);
    }
    
}
